<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/1/11
  Time: 11:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <script type="text/javascript" src="/js/jquery-2.0.3.min.js"></script>
    <meta charset="utf-8" />
    <title>管理系统</title>
    <meta name="keywords" content="管理系统" />
    <meta name="description" content="管理系统" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <link href="/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="/assets/css/font-awesome.min.css" />
    <link rel="stylesheet" href="/assets/css/font-awesome-ie7.min.css" />
    <link rel="stylesheet" href="\assets\css\cyrillic.css" />
    <link rel="stylesheet" href="\assets/css/ace.min.css" />
    <link rel="stylesheet" href="\assets/css/ace-rtl.min.css" />
    <link rel="stylesheet" href="/assets/css/ace-ie.min.css" />
    <script src="/assets/js/html5shiv.js"></script>
    <script src="/assets/js/respond.min.js"></script>
</head>

<body class="login-layout"/>
<script type="text/javascript">
    function register() {
        var username = $("#username").val();
        var password = $("#password").val();
        var rePassword = $("#rePassword").val();
        var email = $("#email").val();
        if (username == "" || password == "" || rePassword == ""||email=="") {
            alert("用户名密码或邮箱不能为空");
        }else{
            $.post(
                "/user/register.do",
                {username:username,password:password,email:email},
                function (data) {
                    if(data==0){
                     alert("用户名已经被使用");
                    }else if(data==1){
                        alert("邮箱已经被注册");
                    }else{
                        alert("注册成功 点击返回登陆页面");
                        window.location.href="/user/toLogin.do";
                    }
                }
            );
        }
    }
    $(function(){
        $("#username").blur(function(){
            var len = $("#username").val().length;
            if(len==0){
                $("#nameError").html("用户名不能为空！");
            }else {
                $("#nameError").html("");
            }
        })
    })
    $(function(){
        $("#password").blur(function(){
            var len = $("#password").val().length;
            if(len==0){
                $("#pwdError").html("密码不能为空！");
            }else {
                $("#pwdError").html("");
            }
        })
    })
    $(function(){
        $("#email").blur(function(){
            var len = $("#email").val().length;
            var email =  $("#email").val();
            //验证邮箱格式正则表达式
            var myreg =  /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
            if(len==0){
                $("#emailError").html("邮箱不能为空！");
                $("#emailMsg").html("");
            }else{
                if (!(myreg.test(email))) {
                    $("#emailMsg").html("");
                    $("#emailError").html("邮箱格式不正确！");
                }
                else {
                    $("#emailError").html("");
                    $("#emailMsg").html("邮箱格式正确！");
                }
            }
        })
    })

    /*
    * 问题：如果第一次输入密码错误后，第二次输入正确，提示消息应该被隐藏。
    * 如何正确设置提示信息
    * */
    $(function(){
        $("#rePassword").blur(function(){
            var pwd1 =  $("#password").val();
            var pwd2 =  $("#rePassword").val();
            var len = $("#rePassword").val().length;
            if(len==0){
                $("#rePwdError").html("密码不能为空！");
                $("#rePwdMsg").html("");
            }else {
                if(!(pwd1 == pwd2)){
                    $("#rePwdError").html("两次输入的密码不一致！");
                    $("#rePwdMsg").html("");
                }else{
                    $("#rePwdError").html("");
                    $("#rePwdMsg").html("两次输入的密码一致");
                }
            }
        })
    })

</script>

<div class="main-container">
    <div class="main-content">
        <div class="row">
            <div class="col-sm-10 col-sm-offset-1">
                <div class="login-container">
                    <div class="center">
                        <h1>
                            <i class="icon-leaf green"></i>
                            <span class="red"></span>
                            <span class="white">管理系统</span>
                        </h1>
                        <h4 class="blue">&copy; 管理系统</h4>
                    </div>

                    <div class="space-6"></div>

                    <div class="position-relative">
                        <div id="login-box" class="login-box visible widget-box no-border">
                            <div class="widget-body">
                                <div class="toolbar clearfix">

                                </div>
                                <div class="widget-main">
                                    <h4 class="header blue lighter bigger">
                                        <i class="icon-coffee green"></i>
                                        注册页面
                                    </h4>

                                    <div class="space-6"></div>

                                    <form>
                                        <fieldset>
                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="text" class="form-control" placeholder="用户名" id="username" name="username" />
                                                            <span style="color: red;" id="nameError"></span>
															<i class="icon-user"></i>
														</span>
                                            </label>
                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="password" class="form-control" placeholder="密码" id="password" name="password" />
                                                            <span style="color: red;" id="pwdError"></span>
															<i class="icon-lock"></i>
														</span>
                                            </label>
                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="password" class="form-control" placeholder="请确认密码" id="rePassword" name="rePassword"/>
                                                            <span style="color: red;" id="rePwdError"></span>
                                                            <span style="color: green;" id="rePwdMsg"></span>
															<i class="icon-lock"></i>
														</span>
                                            </label>
                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input type="email" class="form-control" placeholder="邮箱" id="email" name="email" />
                                                            <span style="color: red;" id="emailError"></span>
                                                            <span style="color: green;" id="emailMsg"></span>

															<i class="icon-lock"></i>
														</span>
                                            </label>

                                            <div class="space"></div>

                                            <div class="clearfix">
                                                <label class="inline">
                                                    <input type="checkbox" style="display:none"/>
                                                    <span class="lbl"> </span>
                                                </label>

                                                <button type="button" onclick="register()" class="width-35 pull-right btn btn-sm btn-primary">
                                                    <i class="icon-key"></i>
                                                    注册
                                                </button>
                                                <button type="button" onclick="window.location.href='/user/toLogin.do'" class="width-35 pull-right btn btn-sm btn-primary">
                                                    <i class="icon-key"></i>
                                                    返回登陆
                                                </button>
                                            </div>

                                            <div class="space-4"></div>
                                        </fieldset>
                                    </form>

                                </div><!-- /widget-main -->
                            </div><!-- /widget-body -->
                        </div><!-- /login-box -->
                            </div><!-- /widget-body -->
                        </div><!-- /signup-box -->
                    </div><!-- /position-relative -->
                </div>
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div>
</div><!-- /.main-container -->



<!-- inline scripts related to this page -->
</body>
</html>